package com.aptemo.webetek.server.handlers;

import com.aptemo.webetek.client.commands.Action;
import com.aptemo.webetek.client.commands.impl.ModifyTeamAction;
import com.aptemo.webetek.client.exceptions.BackendException;
import com.aptemo.webetek.client.exceptions.WebetekLoginException;
import com.aptemo.webetek.client.exceptions.BackendException.EErrorCodes;
import com.aptemo.webetek.server.datastore.DataStoreAPI;
import com.aptemo.webetek.shared.TeamBean;

public class ModifyTeamHandler
		extends ActionHandler<ModifyTeamAction, TeamBean>
{

	public ModifyTeamHandler(DataStoreAPI service)
	{
		super(service);
	}

	public Class<? extends Action<?>> getActionType()
	{
		return ModifyTeamAction.class;
	}

	@Override
	public TeamBean invoke(ModifyTeamAction action) throws BackendException, WebetekLoginException
	{
		utils.checkLogin();

		if (!utils.isTeamEditor(action.getBean().getId()))
		{
			throw new BackendException(EErrorCodes.NOT_TEAM_EDITOR);
		}

		return dataService.modifyTeam(action.getBean());
	}

}
